/*
   Copyright (c) 2011, 2014, 2015 Mizar Tools Contributors (mizartools.org)

   Licensed under the Apache License, Version 2.0 (the "License");
   you may not use this file except in compliance with the License.
   You may obtain a copy of the License at

       http://www.apache.org/licenses/LICENSE-2.0

   Unless required by applicable law or agreed to in writing, software
   distributed under the License is distributed on an "AS IS" BASIS,
   WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
   See the License for the specific language governing permissions and
   limitations under the License.
*/
/*  Contributors :
 *	2011-02-04 Marco Riccardi - initial implementation
 *  2014-12-20 Marco Riccardi - resource leak
 *  2015-01-11 Marco Riccardi - MML 5.22 add tarski_0, tarski_a
 *
 */
package org.mizartools.system;

import java.io.File;
import java.io.FileNotFoundException;
import java.io.FileReader;
import java.io.IOException;
import java.io.LineNumberReader;
import java.util.LinkedList;
import java.util.TreeMap;

public class ListArticleFile {

	private static LinkedList<String> articleList = new LinkedList<String>();
	private static LinkedList<String> allArticleList = new LinkedList<String>();
	private static TreeMap<String,Integer> articleMap = new TreeMap<String, Integer>();
	private static TreeMap<String,Integer> allArticlesMap = new TreeMap<String, Integer>();
	
	static {
		String mizFiles = EnvironFile.getMIZFILES();
		if (mizFiles != null){
			File file = new File(mizFiles, "mml.lar");
			try {
				FileReader fileReader = new FileReader(file);
				try {
					LineNumberReader lineNumberReader = new LineNumberReader(fileReader);
					String inputLine;
					allArticlesMap.put("hidden", 0);
					allArticlesMap.put("tarski_0", 2);
					allArticlesMap.put("tarski_a", 3);
					int i = 4;
					while ((inputLine = lineNumberReader.readLine()) != null){
						articleList.add(inputLine);
						articleMap.put(inputLine, i-4);
						allArticlesMap.put(inputLine, i);
						i++; 
					}
					lineNumberReader.close();
					allArticleList.add("hidden");
					allArticleList.add("tarski_0");
					allArticleList.add("tarski_a");
					allArticleList.addAll(articleList);
				}
				catch (IOException e) {}
				finally{
					try {
						fileReader.close();
						} 
					catch (IOException e) {}
				}
			} catch (FileNotFoundException e) {}
		} 
	}
	
	private ListArticleFile(){
	}

	public static LinkedList<String> getArticleList() {
		return articleList;
	}

	public static LinkedList<String> getAllArticleList() {
		return allArticleList;
	}
	
	public static TreeMap<String, Integer> getArticleMap() {
		return articleMap;
	}

	public static TreeMap<String, Integer> getAllArticleMap() {
		return allArticlesMap;
	}
	

}
